package maps.utils;

//TODO - Use this class everywhere instead of 2 double-fields.
public class Coordinate {
	private final double x;
	private final double y;
	private int cachedHashCode = Integer.MAX_VALUE;

	public Coordinate(double x, double y){
		this.x = x;
		this.y = y;
	}

	public double getX(){
		return x;
	}

	public double getY(){
		return y;
	}

	@Override
	public boolean equals(Object o){
		if (o instanceof Coordinate){
			Coordinate c = (Coordinate) o;
			return ((this.x == c.x) && (this.y == c.y));
		}
		return false;
	}

	@Override
	public int hashCode(){
		if (cachedHashCode == Integer.MAX_VALUE){
			int res = 17;
			long xLong = Double.doubleToLongBits(x);
			int xHash = (int) (xLong ^ (xLong >>> 32));
			res = 31 * res + xHash;
			long yLong = Double.doubleToLongBits(y);
			int yHash = (int) (yLong ^ (yLong >>> 32));
			res = 31 * res + yHash;
			cachedHashCode = res;
		}
		return cachedHashCode;
	}
}
